<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="../js/vue.js"></script>
    <title>列表渲染</title>
</head>
<body>
    <!-- 
        遍历数组，
        遍历对象
        遍历字符串
        遍历指定次数

        key的原理
        虚拟DOM的diff算法是用key来判断的，如果遍历的时候，不写key，vue默认添加index为key

        如果循环中存在输入类DOM，
                会产生错误 ===> 界面有问题
        所以使用唯一标识作为key
     -->
    <div id="app">
        <h1>人员列表</h1>
        <button @click.once="addLL">添加一个老六</button>
        <ul>
            <li v-for="p,index in list" :key='p.id'>
                {{p.name}}-{{p.age}} <input type="text">
            </li>
        </ul>
    </div>
    <script>
        Vue.config.productionTip = false
        const vm = new Vue({
            data(){
                return {
                   list:[
                       {id:'001',name:'张三',age:18},
                       {id:'002',name:'李四',age:19},
                       {id:'003',name:'王五',age:20},
                       {id:'004',name:'小红',age:21},
                   ],
                }
            },
            methods: {
                addLL(){
                    const person = {id:'004',name:'老刘',age:40}
                    this.list.unshift(person)
                }
            },
        }).$mount('#app')
    </script>
</body>
</html>